package b2.player
{
	public class TankPackage
	{
		public var tankList:Array;
		
		public function TankPackage(packageXML:XML = null)
		{
			tankList = new Array();
			if (packageXML != null)
			{
				for (var i:int = 0; i < packageXML.tank.length(); i++)
				{
					var tankInfo:TankInfo = new TankInfo(packageXML.tank[i]);
					PlayerInfoManager.getInstance().tanks[tankInfo.id] = tankInfo;
					tankList.push(tankInfo.id);
				}
			}
		}
		
		public function sortWithFightPoint():void
		{
			tankList.sort(compareWithFightPoint);
		}
		
		private function compareWithFightPoint(a:int, b:int):int
		{
			var tankA:TankInfo = PlayerInfoManager.getInstance().tanks[a];
			var tankB:TankInfo = PlayerInfoManager.getInstance().tanks[b];
			if (tankA.fightPoint > tankB.fightPoint)
				return -1;
			else if (tankA.fightPoint < tankB.fightPoint)
				return 1;
			else
				return 0;
		}
		
		public function deleteTank(tankId:int):void
		{
			//找到位置
			var i:int = tankList.indexOf(tankId);
			for (;i < tankList.length - 1; i ++)
			{
				tankList[i] = tankList[i+1];	
			}
			tankList.pop();
		}

	}
}